package fromnet;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;

public class NetShowFile {

	public static TextBox getATextBoxOfFile(String filePath) {
		TextBox tb = new TextBox("View File", null, 1024, TextField.ANY
				| TextField.UNEDITABLE);

		try {
			FileConnection fc = (FileConnection) Connector.open(filePath);

			if (!fc.exists()) {
				throw new IOException("File does not exists");
			}
			InputStream fis = fc.openInputStream();
			byte[] b = new byte[1024];
			int length = fis.read(b, 0, 1024);
			fis.close();
			fc.close();


			if (length > 0) {
				tb.setString(new String(b, 0, length));
			}

		} catch (Exception e) {
			System.out.println(e);
		}
		return tb;
	}
}
